package com.abocode.aichat.server.context.worker;

import com.abocode.aichat.server.context.channel.ChannelWrapper;
import com.abocode.aichat.server.context.delivery.reply.Replies;
import com.abocode.aichat.data.MessageStanza;
import com.abocode.aichat.server.modules.ModuleHandler;
import io.netty.channel.Channel;

/**
 * @author guanxf
 */
public class ProtocolMessageStanzaWorker extends MessageStanzaWorker {
    @Override
    public void execute(Channel channel, MessageStanza stanza) {
        ModuleHandler stanzaHandler = stanzaHandlerContext.get(stanza);
        ChannelWrapper channelWrapper = serverRuntimeContext.getProtocolChannelRegistry().get(channel);
        if (channelWrapper == null) {
            throw new RuntimeException("channelWrapper is not register");
        }
        Replies replies = stanzaHandler.handler(channelWrapper, stanza);
        serverRuntimeContext.getInboundServerDeliver().deliver(replies, stanza);
    }
}
